import request from '@/utils/request'

export function getList(modelName, params) {
  return request({
    url: `/${modelName}-list`,
    params,
    method: 'get'
  })
}

export function uploadItem(modelName, data) {
  return request({
    url: `/${modelName}`,
    data,
    method: 'post'
  })
}

export function uploadItemByUrl(modelName, data) {
  return request({
    url: `/${modelName}-url`,
    data,
    method: 'post'
  })
}

export function updateAttrById(modelName, attributeName, id, data) {
  return request({
    url: `/${modelName}/${id}/${attributeName}`,
    data,
    method: 'put'
  })
}

export function updateNameById(modelName, id, data) {
  return request({
    url: `/${modelName}/${id}/name`,
    data,
    method: 'put'
  })
}

export function updateAuthorById(modelName, id, data) {
  return request({
    url: `/${modelName}/${id}/author`,
    data,
    method: 'put'
  })
}

export function updateDescById(modelName, id, data) {
  return request({
    url: `/${modelName}/${id}/desc`,
    data,
    method: 'put'
  })
}

export function updateCatalogById(modelName, id, data) {
  return request({
    url: `/${modelName}/${id}/catalog`,
    data,
    method: 'put'
  })
}

export function updateCoverById(modelName, id, data) {
  return request({
    url: `/${modelName}/${id}/cover`,
    data,
    method: 'put'
  })
}

export function deleteItem(modelName, id) {
  return request({
    url: `/${modelName}/${id}`,
    method: 'delete'
  })
}
